package org.x.legalcasemod.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.x.commonmod.config.Result;
import org.x.legalcasemod.dto.AllocationLawyerDTO;
import org.x.legalcasemod.dto.GetCaseListDTO;
import org.x.legalcasemod.dto.OperatorCseDTO;
import org.x.legalcasemod.entity.LegalCaseEntity;
import org.x.legalcasemod.service.IApplyCaseService;
import org.x.legalcasemod.service.ICaseManagementService;
import org.x.legalcasemod.vo.AcceptCaseVO;
import org.x.legalcasemod.vo.GetCaseDetailVO;
import org.x.legalcasemod.vo.GetCaseListVO;

;

/**
 * 案件表 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@RestController
@RequestMapping("/api/cases")
public class CaseManagementController {
    @Autowired
    private ICaseManagementService legalCaseService;

    @Autowired
    private IApplyCaseService applyCaseService;

    /**
     * 申请案件或保存草稿
     * @param operatorCaseDTO
     * @return
     */
    @PostMapping
    public Result operatorCase(@RequestBody OperatorCseDTO operatorCaseDTO){
        applyCaseService.operatorCase(operatorCaseDTO);
        return Result.ok("操作成功");

    }
    /**
     * 获取案件列表(分页)
     * @param getCaseListDTO
     * @return
     */
    @PostMapping("/list")
    public Result getCaseList(@RequestBody GetCaseListDTO getCaseListDTO){
        GetCaseListVO result =legalCaseService.getCaseList(getCaseListDTO);
        return Result.ok(result);
    }

    /**
     * 分配律师
     * @param allocationLawyerDTO
     * @return
     */
    @PostMapping("/assign")
    public Result allocationLawyer(@RequestBody AllocationLawyerDTO allocationLawyerDTO){
        legalCaseService.allocationLawyer(allocationLawyerDTO);
        return Result.ok("分配成功");
    }

    /**
     * 案件接收
     * @param caseId
     * @return
     */
    @PostMapping("/accept")
    public Result acceptCase(@RequestParam("caseId")Long caseId){
        AcceptCaseVO acceptCaseVO =legalCaseService.acceptCase(caseId);
        return Result.ok("案件接受成功",acceptCaseVO);
    }

    /**
     * 获取案件详情
     * @param caseNo
     * @return
     */
    @GetMapping("/detail")
    public  Result getCaseDetail(@RequestParam("caseNo")String caseNo){
        GetCaseDetailVO getCaseDetailVO = legalCaseService.getCaseDetail(caseNo);
        return Result.ok("案件详情",getCaseDetailVO);
    }

}